import bean.Person;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.ext.DefaultHandler2;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;

public class t1 {
    static ArrayList<Person> people;
    static Person person;
    public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException {
        SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();

        MySAX mySAX = new MySAX();
        saxParser.parse(t1.class.getResourceAsStream("/person.xml"),mySAX);
    }
    static class MySAX extends DefaultHandler2 {
        @Override
        public void startCDATA() throws SAXException {
            System.out.println("startCDATA");
        }

        @Override
        public void endCDATA() throws SAXException {
            System.out.println("endCDATA");
        }

        @Override
        public void startDocument() throws SAXException {
/*            person = new Person();
            people.add(person);*/
        }

        @Override
        public void endDocument() throws SAXException {
            System.out.println("endDocument");
        }

        @Override
        public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
            System.out.println("startElement");
            System.out.println(uri);
            System.out.println(localName);
            System.out.println(qName);
            System.out.println(attributes);
        }

        @Override
        public void endElement(String uri, String localName, String qName) throws SAXException {
            System.out.println("startElement");
            System.out.println(uri);
            System.out.println(localName);
            System.out.println(qName);
        }

        @Override
        public void characters(char[] ch, int start, int length) throws SAXException {
            System.out.println("characters");
            System.out.println(new String(ch,start,length));
            System.out.println(start);
            System.out.println(length);
        }
    }
}
